package com.studyweb.service.impl;

import com.studyweb.mapper.ShenLunItemMapper;
import com.studyweb.pojo.entity.ShenLunItem;
import com.studyweb.service.ShenLunItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ShenLunItemServiceImpl implements ShenLunItemService {
    
    @Autowired
    private ShenLunItemMapper shenLunItemMapper;
    
    @Override
    public boolean addShenLunItem(ShenLunItem shenLunItem) {
        return shenLunItemMapper.insert(shenLunItem) > 0;
    }
    
    @Override
    public boolean deleteShenLunItem(Long id) {
        return shenLunItemMapper.deleteById(id) > 0;
    }
    
    @Override
    public boolean deleteShenLunItems(List<Long> ids) {
        return shenLunItemMapper.deleteBatch(ids) > 0;
    }
    
    @Override
    public boolean updateShenLunItem(ShenLunItem shenLunItem) {
        return shenLunItemMapper.update(shenLunItem) > 0;
    }
    
    @Override
    public ShenLunItem getShenLunItemById(Long id) {
        return shenLunItemMapper.selectById(id);
    }
    
    @Override
    public List<ShenLunItem> getAllShenLunItems() {
        return shenLunItemMapper.selectAll();
    }
    
    @Override
    public List<ShenLunItem> getShenLunItemsByCondition(String category, String subCategory) {
        // 处理空字符串情况，将其转换为null
        if (category != null && category.isEmpty()) {
            category = null;
        }
        if (subCategory != null && subCategory.isEmpty()) {
            subCategory = null;
        }
        return shenLunItemMapper.selectByCondition(category, subCategory);
    }
}